/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vera.hibernate.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import vera.hibernate.entity.BillHeader;
import vera.hibernate.util.HibernateUtil;

/**
 *
 * @author vgncr35g
 */
public class BillHeaderDAO extends EntityDAO {
    
    public BillHeaderDAO()
    {
        // do nothing
    }
    
    public BillHeader getBillHeader(int billNum)
    {
       Session s = HibernateUtil.openSession();
       Query q = s.getNamedQuery("getBillHeader");
       q.setInteger("billNum", billNum);
       BillHeader bh = (BillHeader) q.uniqueResult();
       s.close();
       return bh;
    }
    
    public List<BillHeader> getAllBillHeaders()
    {
       Session s = HibernateUtil.openSession();
       Query q = s.getNamedQuery("getBillHeaders");
       List<BillHeader> billHeaders = q.list();
       s.close();
       return billHeaders;
    }
    
    public List<BillHeader> getAllBillHeadersByClient(int clientCd)
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getBillHeadersByClient");
        q.setInteger("clientCd", clientCd);
        List<BillHeader> billHeaders = q.list();
        s.close();
        return billHeaders;
    }
    
    public void deleteBillHeader(int billNum)
    {
        BillHeader bh = getBillHeader(billNum);
        deleteEntity(bh);
    }
}
